package com.kfm.storage.util;

/**
 * @author Aurora雪
 */


import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.Enumeration;
import java.util.Properties;

/**
 * 服务器类
 */
public class Server {

    private String remoteIpAddress;
    private int remotePort;
    private String localFolderPath;

    /**
     * 从配置文件中加载配置
     */
    public void loadConfig() {
        InputStream input = null;
        try {
            Properties prop = new Properties();
            input = null;

            try {
                // 读取配置文件
                input = getClass().getClassLoader().getResourceAsStream("server.properties");
                prop.load(input);

                remoteIpAddress = prop.getProperty("remoteIpAddress");
                remotePort = Integer.parseInt(prop.getProperty("remotePort"));
                localFolderPath = prop.getProperty("localFolderPath");


            } catch (IOException ex) {
                ex.printStackTrace();
            } finally {
                if (input != null) {
                    try {
                        input.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
        } catch (RuntimeException e) {
            throw new RuntimeException(e);
        }
    }

    public String getRemoteIpAddress() {
        return remoteIpAddress;
    }

    public int getRemotePort() {
        return remotePort;
    }

    public String getLocalFolderPath() {
        return localFolderPath;
    }
}
